using System;
using System.Collections.Generic;

namespace Managistics.Model
{
    [Serializable()]
    public class PurchaseOrderDetail : Entity<double>
    {
        private string _orderidNn;
        private string _itemId;
        private PurchaseOrder _orderNhanhNhanh;
        private Good _good;
        private float _quantityNn;
        private float? _discountNn;
        private float _unitPriceNn;
        private bool? _statusItemFd;
        private short _vat;
        private double _id;
        public virtual string Orderid
        {
            get
            {
                return this._orderidNn;
            }
            set
            {
                this._orderidNn = value;
            }
        }
        public virtual string ItemId
        {
            get
            {
                return this._itemId;
            }
            set
            {
                this._itemId = value;
            }
        }
        public virtual PurchaseOrder PurchaseOrder
        {
            get
            {
                return this._orderNhanhNhanh;
            }
            set
            {
                this._orderNhanhNhanh = value;
            }
        }
        public virtual Good Good
        {
            get
            {
                return this._good;
            }
            set
            {
                this._good = value;
            }
        }
        public virtual float Quantity
        {
            get
            {
                return this._quantityNn;
            }
            set
            {
                this._quantityNn = value;
            }
        }
        public virtual float? Discount
        {
            get
            {
                return this._discountNn;
            }
            set
            {
                this._discountNn = value;
            }
        }
        public virtual float UnitPrice
        {
            get
            {
                return this._unitPriceNn;
            }
            set
            {
                this._unitPriceNn = value;
            }
        }
        public virtual bool? StatusItem
        {
            get
            {
                return this._statusItemFd;
            }
            set
            {
                this._statusItemFd = value;
            }
        }
        public virtual short Vat
        {
            get
            {
                return this._vat;
            }
            set
            {
                this._vat = value;
            }
        }
        public virtual double Id
        {
            get
            {
                return this._id;
            }
            set
            {
                this._id = value;
            }
        }

        public virtual float AmountNotVat
        {
            get
            {
                return this._unitPriceNn * this._quantityNn;
            }
        }

        public virtual float AmountVat
        {
            get
            {
                return this.AmountNotVat * this._vat / 100;
            }
        }

        public virtual float AmountIncludedVat
        {
            get
            {
                return this.AmountNotVat + this.AmountVat;
            }
        }

        #region NHibernate Composite Key Requirements
        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            var t = obj as PurchaseOrderDetail;
            if (t == null) return false;
            if (Orderid == t.Orderid
             && ItemId == t.ItemId)
                return true;

            return false;
        }
        public override int GetHashCode()
        {
            int hash = GetType().GetHashCode();
            hash = (hash * 397) ^ Orderid.GetHashCode();
            hash = (hash * 397) ^ ItemId.GetHashCode();

            return hash;
        }
        #endregion
    }

}
